package com.lambda.use;


import org.junit.Test;

import java.util.function.Predicate;

/**
 * 功能描述
 *
 * @author: jichao.huang
 * @date: 2025年06月04日 16:45
 */
public class PredicateUseTest {
    @Test
    public void testTest(){
        Predicate<String> predicate = (s) -> s.length() > 0;
        System.out.println(predicate.test("foo"));
        System.out.println(predicate.test(""));

        Predicate<String> predicate2 = String::isEmpty;
        System.out.println(predicate2.test("foo"));
        System.out.println(predicate2.test(""));

    }

    @Test
    public void testNegate(){
        Predicate<String> predicate = (s) -> s.length() > 0;
        System.out.println(predicate.negate().test("foo"));
        System.out.println(predicate.negate().test(""));
    }

    @Test
    public void testAnd(){
        Predicate<String> predicate = (s) -> s.length() > 0;
        Predicate<String> predicate2 = (s) -> s.length() < 3;
        System.out.println(predicate.and(predicate2).test("foo"));
        System.out.println(predicate.and(predicate2).test(""));
    }

    @Test
    public void testOr(){
        Predicate<String> predicate = (s) -> s.length() > 0;
        Predicate<String> predicate2 = (s) -> s.length() < 3;
        System.out.println(predicate.or(predicate2).test("foo"));
        System.out.println(predicate.or(predicate2).test(""));
    }

    @Test
    public void testIsEqual(){
        Predicate<String> predicate = Predicate.isEqual("abc");
        System.out.println(predicate.test("abc"));
        System.out.println(predicate.test(""));
    }
}
